
Page({
  data: {
    wd: '',
    list: [],
    page: 1,
    size: 20,
    hasNextPage: true
  },
  search() {
    // console.log(this.data.wd)
    const self = this
    wx.request({
      url: `http://localhost:3000/girls/?q=${self.data.wd}`,
      success(res) {
        self.setData({
          list: res.data,
          page: 1,
          hasNextPage: true
        })
      }
    })
  },
  onLoad() {
    this.getList()
  },
  getList (options) {
    const self = this
    const { size, page } = self.data
    wx.request({
      url: `http://localhost:3000/girls/?_page=${page}&_limit=${size}`,
      success(res) {
        self.setData({
          list: [...self.data.list, ...res.data]
        })
        if (res.data.length < self.data.size) {
          self.setData({
            hasNextPage: false
          })
        }
      }
    })
  },
  onReachBottom () {
    const self = this
    if (self.data.hasNextPage) {
      self.setData({
        page: self.data.page + 1
      })
      self.getList()
    }
  },
})